#include "player.h"
#include <ctime>
#include <iostream>
#include <cstdio>
using namespace std;
player::player(int pcode)
{
	x = 384;
	y = 256;
	current_location_code = 0;
	player_code = pcode;
	money = 750;
	is_jail = 0;
	is_get_out_card = 0;
	turns_since_free = 0;
	is_eliminated = 0;
	for (int i = 0; i < 20; i++)
	{
		properties[i] = 0;
		//is_house[i] = 0;
		//is_hotel[i] = 0;
	}
}

int player::net_worth(location loc_arr[])
{
	int total;
	total = money;
	for (int i = 0; i < 20; i++)
	{
		if (properties[i] == 1)
		{
			total += ((loc_arr[i].price) / 2);
		}
	}
	return total;
}

char *player::rand_dice(int i, location loc_arr[])
{
	//cout << "It's player " << player_code << "'s turn" << "\n" << endl;
	 move1 = 0, move2 = 0;
	while (move1 == 0 || move2 == 0)
	{
		move1 = rand() % 7;
		move2 = rand() % 7;
	}
	//cout << move1 << ' ' << move2 << " RAND_DICE FUNCTION, MOVE 1 AND MOVE 2" << endl;
	move = move1;
	//traversal();
	//cout << "You rolled " << move1 << " and " << move2 << endl;
	//cout << "You move " << move << "steps" << endl;
	int temp = move;
	while (temp!=0)
	{
		if (current_location_code == 19)
		{
			current_location_code = 0;
			money += 100;
		}
		else current_location_code++;
		temp--;
	}
	x = loc_arr[current_location_code].x;
	y = loc_arr[current_location_code].y;
	char str[1000];
	if (current_location_code == 15)
	{
		current_location_code = 5;
		x = 0;
		y = 256;
		is_jail = 1;
		turns_since_free = 3;
		sprintf_s(str, "Rolled %d\n. Player %d landed in Go To Jail", move1, player_code+1);
		return str;
	}
	else
	{
		sprintf_s(str, "Rolled %d Player %d lands at %s", move1, player_code+1, loc_arr[current_location_code].name);
		printf("%s\n", str);
		return str;
	}
	
}

int player::isequal()
{
	if (move1 == move2)
	{
		return 1;
	}
}

/*void player::traversal()
{
	cout << move << endl;
	for (int i = 0; i < move; i++)
	{
		if (x == 5 && y != 0)y--;
		else if (x == 5 && y == 0)x--;
		else if (y == 0 && x != 0)x--;
		else if (y == 0 && x == 0)y++;
		else if (x == 0 && y != 5)y++;
		else if (x == 0 && y == 5)x++;
		else if (y == 5 && x != 5)x++;
		else if (y == 5 && x == 5)y--;
		if (x == 5 && y == 5)money += 200;
		cout << x << ' ' << y << " TRAVERSAL FUNCTION, X AND Y" << endl;
	}
	while (1)
	{

	}
}*/
/*void player::traversal(int movement)
{
	cout << movement << endl;
	for (int i = 0; i < movement; i++)
	{
		if (x == 5 && y != 0)y--;
		else if (x == 5 && y == 0)x--;
		else if (y == 0 && x != 0)x--;
		else if (y == 0 && x == 0)y++;
		else if (x == 0 && y != 5)y++;
		else if (x == 0 && y == 5)x++;
		else if (y == 5 && x != 5)x++;
		else if (y == 5 && x == 5)y--;
		cout << x << ' ' << y << " TRAVERSAL FUNCTION, X AND Y" << endl;
	}
}*/
player::~player()
{
}
